/**
 * 
 */
package com.swim.traininfo.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.swim.pay.web.SwimPayController;
import com.swim.traininfo.entity.TrainInfo;
import com.swim.traininfo.service.TrainInfoService;

/**
 * 培训资讯Controller
 * @author 刘军武
 * @version 2021-04-25
 */
@Controller
@RequestMapping(value = "${adminPath}/traininfo/trainInfo")
public class TrainInfoController extends BaseController {

	@Autowired
	private TrainInfoService trainInfoService;

    private Logger logger = LoggerFactory.getLogger(SwimPayController.class);
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TrainInfo get(String id, boolean isNewRecord) {
		return trainInfoService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("traininfo:trainInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(TrainInfo trainInfo, Model model) {
		logger.error("######### 查询培训资讯操作 #########");
		model.addAttribute("trainInfo", trainInfo);
		return "swim/traininfo/trainInfoList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TrainInfo> listData(TrainInfo trainInfo, HttpServletRequest request, HttpServletResponse response) {
		Page<TrainInfo> page = trainInfoService.findPage(new Page<TrainInfo>(request, response), trainInfo); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("traininfo:trainInfo:view")
	@RequestMapping(value = "form")
	public String form(TrainInfo trainInfo, Model model) {
		model.addAttribute("trainInfo", trainInfo);
		return "swim/traininfo/trainInfoForm";
	}

	/**
	 * 保存培训资讯
	 */
	@RequiresPermissions("traininfo:trainInfo:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TrainInfo trainInfo) {
		trainInfoService.save(trainInfo);
		return renderResult(Global.TRUE, text("保存培训资讯成功！"));
	}
	
	/**
	 * 删除培训资讯
	 */
	@RequiresPermissions("traininfo:trainInfo:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TrainInfo trainInfo) {
		trainInfoService.delete(trainInfo);
		return renderResult(Global.TRUE, text("删除培训资讯成功！"));
	}
	
}